package cli.menu;
import java.util.Scanner;
import cli.tools.Tools;
//@author A0085686L
/*by LI YIN
*/

public class SearchReceiptSelectFilter extends Function{
	private static final String[] reqInput = {
		"-= Main menu > Search > Receipt Tracking =-",
		"[b]: back [u]: undo [r]: redo [h]: home menu",
		"What would you like to filter your search results by?",
		"1. Item Name",
		"2. Purchasing Date",
		"3. Shop Name",
		"4. Serial Number",
		"5. Model",
		"6. Brand"
	};
	
	private static State back = State.SEARCHSELECTFILTER;
	private static State current = State.SEARCHRECEIPTSELECTFILTER;
	
	public static State runMenu(){
		
		cli.print(reqInput);
		String input = cli.nextLine();
		
		if(input.length() == 1){
			char charInput = input.charAt(0);
			if(tools.isHotKey(charInput))
				return hotKeyFunction(charInput);
			else return normFunction(charInput);
		}
		cli.print(INVALIDINPUT);
		return current;
	}
	
	//if is menu selection
	private static State normFunction(char input){
		
		State nextState = current;
		switch (input) {
			case '1':
				nextState = State.SEARCHBYITEMNAME;
				break;
			case '2':
				nextState = State.SEARCHBYPURCHASINGDATE;
				break;
			case '3':
				nextState = State.SEARCHBYSHOP;
				break;
			case '4':
				nextState = State.SEARCHBYSERIALNUM;
				break;
			case '5':
				nextState = State.SEARCHBYMODEL;
				break;
			case '6':
				nextState = State.SEARCHBYBRAND;
				break;
			default:
				cli.print(INVALIDINPUT);
				break;
		}
	
		return nextState;
	}
	
	//check hotkey
	private static State hotKeyFunction(char charInput){
		State nextState = current;
		switch (charInput) {
			case 'u':
			case 'U':
				tools.undo();
				break;
			case 'r':
			case 'R':
				tools.redo();
				break;
			case 'h':
			case 'H':
				nextState = State.MAINMENU;
				break;
			case 'b':
			case 'B':
				nextState = back;
				break;
			default:
				break;
		}	
		return nextState;
	}
}
